<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @cancel="handleCancel">
    <template #footer>
      <a-button key="1" @click="handleCancel">关闭</a-button>
    </template>

      <a-button style="margin-bottom:10px" type="primary" @click="downLoadFile('征集意见人员列表')">下载</a-button>

      <a-table
        ref="table"
        size="middle"
        rowKey="id"
        bordered
        :scroll="{ y: 500 }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="rightLoading"
        @change="ipagination.current = $event.current;ipagination.pageSize=$event.pageSize;getRightData()"/>

  </j-modal>
</template>

<script>
import { getAction, downFile } from '@/api/manage'
import leftTreeData from '../comp/leftTreeData'

export default {
  name: 'ReadingSituation',
  components:{
    leftTreeData
  },
  props:{
    // 区分是通知公告or意见征集
    formType:{
      type: String,
      default: 'notice'
    },
    publishId:{
      type: String,
      default:''
    },
  },
  data () {
    return {
      title:'',
      width:1400,
      visible: false,
      rightLoading: false,
      disableSubmit: false,
      loading: false,
      orgCode:'',
      dataSource: [],//右侧列表数据
      empOpinionList: '/api/erp/publishCollect/emp/feedbackOpinionList',
      exportXlsUrl: '/api/erp/publishCollect/emp/feedback/exportXls',
      columns:[{
                title: '序号',
                width:60,
                dataIndex:'id',
                align:"center",
                customRender:function (t,r,index) {
                return parseInt(index)+1;
                }
            },{
                title:'部门',
                align:"center",
                dataIndex:'empDepartIds_dictText',
                ellipsis: true,
            },{
                title:'人员',
                align:"center",
                dataIndex: 'empId_dictText',
                ellipsis: true,
            },{
                title:'征集意见',
                align:"center",
                dataIndex:'feedbackOpinion',
                ellipsis: true,
            }],
      ipagination:{
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
    }
  },
  methods: {
    // 初始化
    init () {
      this.visible=true
      this.title='征集意见'
      this.getRightData()
     
    },
    // 右侧数据获取
    async getRightData(){
      this.rightLoading = true
      let res = await getAction(this.empOpinionList,{
        collectId: this.publishId,
        pageNo: this.ipagination.current,
        pageSize: this.ipagination.pageSize
      })
      this.rightLoading = false
      if(res.success){
        const {records,current,total} = res.result

        this.ipagination.total= total || 0

        this.dataSource = records
      }else{
        this.dataSource = []
      }
    },
    async downLoadFile(fileName){
      if (!fileName || typeof fileName !== 'string') {
        fileName = '导出文件'
      }
      downFile(this.exportXlsUrl, {collectId: this.publishId}).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            }),
            fileName + '.xls'
          )
        } else {
          let url = window.URL.createObjectURL(
            new Blob([data], {
              type: 'application/vnd.ms-excel'
            })
          )
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
      }).finally(()=>{
        // this.exportLoading = false
      })

    },
    handleCancel () {
      this.$emit('close')
      this.visible = false
    },
  }
}
</script>